home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1996 October
/
MACPOWER-1996-10.ISO.7z
/
MACPOWER-1996-10.ISO
/
AMUG
/
Internet_31
/
NetCacheResolver 0.9d6
/
NetCacheResolver 0.9d6 ト
/
library
/
NCR_Event.c
< prev
next >
Wrap
Text File
|
1996-05-12
|
8KB
|
402 lines
// NetCache Resolver, 1995 (C) Mizutori Tetsuya
// - NCR_Event.c, October 8, 1995
// This document is pretty printed in 10-point Geneva font.
#include "NCR_Basic.h"
#include "NCR_Event.h"
#ifdef DEBUG
#include "NCR_Message.h"
#endif /* DEBUG */
// definition
// global
Boolean gDone = false;
Boolean gAEOpenAppl = false;
Boolean gAEOpenDocs = false;
Boolean gAEPrintDoc = false;
Boolean gAEQuitAppl = false;
// callback function, defined in 'main.c'
extern OSErr DoOpen ( WindowPtr window );
// prototype
/***** DoEvent *****/
static void DoEvent ( EventRecord *event );
static OSErr MyInspectAppleEvent ( const EventRecord *event );
/***** Do suspent & resume *****/
static void DoSuspendResume ( EventRecord *event );
/***** Do Activate & Update*****/
static void DoActivate ( WindowPtr window, Boolean becomingActive );
static void DoUpdate ( WindowPtr window, EventRecord *event );
/***** HandleMouseDown *****/
static void HandleMouseDown ( EventRecord *eventPtr );
static void DoContent ( WindowPtr window, EventRecord *event );
static void DoKeyDown ( short c );
/***** Handle MenuChoice *****/
static void HandleMenuChoice ( long menuChoice );
static void HandleAppleChoice ( short item );
static void HandleFileChoice ( short item );
static void HandleEditChoice ( short theItem );
/***** setup *****/
void ToolboxInit ( void )
{
long i;
for ( i=0; i<5; i++ ) MoreMasters(); // allocates a block of 64 Handles
InitGraf( &qd.thePort );
InitFonts();
InitWindows();
InitMenus();
FlushEvents( everyEvent, 0 );
TEInit();
InitDialogs( (long) nil );
InitCursor();
AEObjectInit(); // for AppleScript Resolver
ZeroScrap();
MaxApplZone();
}
//#define kMenuBarID 128
//#define mApple 128
//#define mFile mApple+1
//#define mEdit mApple+2
//#define mPosition 100
#define kNotANormalMenu -1
void SetupMenuBar ( void )
{
Handle menuBar;
MenuHandle menu;
OSErr err;
menuBar = GetNewMBar( kMenuBarID );
if ( menuBar == nil ) return;
SetMenuBar( menuBar );
menu = GetMenuHandle( mApple );
AppendResMenu( menu, 'DRVR' );
// menu = GetMenu( mFont );
// AppendResMenu( menu, 'FONT' );
// InsertMenu( menu, kNotANormalMenu );
menu = GetMenu( mPosition );
InsertMenu( menu, kNotANormalMenu );
DrawMenuBar();
}
/***** EventLoop *****/
#define kSleep 10000000L
void EventLoop ( void )
{
EventRecord event;
#ifdef DEBUG
Message("Starting EventLoop ...¥n");
#endif /* DEBUG */
gDone = false;
gAEOpenAppl = false;
gAEOpenDocs = false;
gAEQuitAppl = false;
while ( true ) {
if ( !gAEOpenAppl && gAEOpenDocs ) break;
if ( gAEOpenAppl && gDone ) break;
if ( gAEQuitAppl ) break;
if ( WaitNextEvent( everyEvent, &event, kSleep, nil ) )
DoEvent( &event );
SystemTask();
}
}
/***** DoEvent *****/
static void DoEvent ( EventRecord *event )
{
short theChar;
Boolean toActive;
switch ( event->what ) {
case kHighLevelEvent:
if ( event->message == kCoreEventClass )
switch ( *((long *) (&(event->where))) ) {
case kAEOpenApplication: gAEOpenAppl = true; break;
case kAEOpenDocuments: gAEOpenDocs = true; break;
case kAEPrintDocuments: gAEPrintDoc = true; break;
case kAEQuitApplication: gAEQuitAppl = true; break;
default: break;
}
MyInspectAppleEvent( event );
AEProcessAppleEvent( event );
break;
case mouseDown:
HandleMouseDown( event );
break;
case mouseUp:
case keyUp:
break;
case keyDown:
case autoKey:
theChar = event->message & charCodeMask;
if ( (event->modifiers & cmdKey) != 0 ) {
//AdjustMenu();
HandleMenuChoice( MenuKey( theChar ) ); }
else
DoKeyDown( (unsigned char) theChar );
break;
case updateEvt:
DoUpdate( (WindowPtr) (event->message), event );
break;
case activateEvt:
toActive = ( (event->modifiers & activeFlag) == activeFlag );
DoActivate( (WindowPtr) (event->message), toActive );
break;
case diskEvt:
case networkEvt:
case driverEvt:
case app1Evt:
case app2Evt:
case app3Evt:
break;
case osEvt:
DoSuspendResume( event );
}
}
/***** Inspect Event Record *****/
static OSErr MyInspectAppleEvent ( const EventRecord *event )
{
OSType eventClass, classID;
if ( event->what != kHighLevelEvent ) return noErr;
eventClass = (OSType) event->message;
classID = * (OSType *) &(event->where);
#ifdef DEBUG
Message("===: eventClass('%T') classID('%T')¥n", eventClass, classID );
#endif /* DEBUG */
return noErr;
}
/***** Do suspent & resume *****/
static void DoSuspendResume ( EventRecord *event )
{
WindowPtr window;
long message;
window = FrontWindow();
message = event->message;
switch ( ( message >> 24 ) & 0xFF ) {
case mouseMovedMessage:
break;
case suspendResumeMessage:
switch ( ( message & 0x03 ) ) {
case 1: /* Resume */
DoActivate( window, true );
break;
case 2: /* Suspend */
DoActivate( window, false );
break;
case 3: /* Clipboard changed */
break;
}
break;
}
}
/***** Do Activate *****/
static void DoActivate ( WindowPtr window, Boolean becomingActive )
{
GrafPtr oldPort;
GetPort( &oldPort );
SetPort( window );
if ( becomingActive ) {
/* do activate, here */
} else {
/* do deactivate, here */
}
SetPort( oldPort );
}
/***** Do Update *****/
static void DoUpdate ( WindowPtr window, EventRecord *event )
{
GrafPtr oldPort;
GetPort( &oldPort );
SetPort( window );
BeginUpdate( window );
/* redraw window, here */
EndUpdate( window );
SetPort( oldPort );
}
/***** HandleMouseDown *****/
static void HandleMouseDown ( EventRecord *event )
{
WindowPtr window;
long menuChoice;
long thePart;
thePart = FindWindow( event->where, &window );
switch( thePart ) {
case inMenuBar:
//AdjustMenu();
menuChoice = MenuSelect( event->where );
HandleMenuChoice( menuChoice );
break;
case inSysWindow:
SystemClick( event, window );
break;
case inContent:
if ( window != FrontWindow() ) {
SelectWindow( window );
} else {
DoContent( window, event );
}
break;
case inDrag:
DragWindow( window, event->where, &qd.screenBits.bounds );
break;
case inGoAway:
if ( TrackGoAway( window, event->where ) )
gDone = true;
break;
case inZoomIn:
case inZoomOut:
if ( TrackBox( window, event->where, thePart ) ) {
/* do nothing, here */
}
break;
}
}
static void DoContent ( WindowPtr window, EventRecord *event )
{
}
static void DoKeyDown ( short c )
{
}
/***** Handle MenuChoice *****/
static void HandleMenuChoice ( long menuChoice )
{
short menu;
short item;
if ( menuChoice != 0 ) {
menu = HiWord( menuChoice );
item = LoWord( menuChoice );
switch ( menu ) {
case mApple:
HandleAppleChoice( item );
break;
case mFile:
HandleFileChoice( item );
break;
case mEdit:
HandleEditChoice( item );
break;
default:
break; }
HiliteMenu( 0 );
}
}
/***** Handle Apple Choice *****/
#define kAboutID 130
static void HandleAppleChoice ( short item )
{
MenuHandle appleMenu;
Str31 accName;
short accNumber;
switch ( item ) {
case iAbout:
Alert( kAboutID, nil );
break;
default:
appleMenu = GetMHandle( mApple );
GetItem( appleMenu, item, accName );
accNumber = OpenDeskAcc( accName );
break;
}
}
/***** Handle File Choice *****/
static void HandleFileChoice ( short item )
{
WindowPtr window;
window = FrontWindow();
switch ( item ) {
case iQuit:
gDone = true;
break;
case iOpen:
DoOpen( window );
break;
case iNew:
case iClose:
case iSave:
case iSaveAs:
case iPageSetup:
case iPrint:
case iPreferences:
default:
break;
}
}
/***** Handle Edit Choice *****/
static void HandleEditChoice ( short theItem )
{
WindowPtr window;
short item;
if ( SystemEdit( theItem - 1 ) ) return;
window = FrontWindow();
switch ( theItem ) {
case iUndo:
case iCut:
case iCopy:
case iPaste:
case iClear:
case iDuplicate:
case iSelectAll:
default:
break;
}
}
// end of program